
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
	isELIgnored="false"%>
<html>
<head>
<title>物流配送管理系统</title>
<link rel="stylesheet" type="text/css" href="../../css/readerTyper.css" />
<script type="text/javascript" src="../../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../../js/car.js"></script>
</head>
<body style="font-size: 20px">
	<%@ include file="navigation.jsp"%>
	<div id="content">
		<p valign="top" id="p">当前位置：车辆管理&gt; 车队管理 &gt;&gt;添加车辆信息
			&gt;&gt;&gt;</p>
		<div>
			<form method="post"
				action="/addcar.do"
				onsubmit="return checkform()">
				<table border="1" cellpadding="0" cellspacing="0">
					<tr>
						<td class="t1">车牌号：</td>
						<td><input name="carId" type="text" id="carId" class="c1"
							placeholder="请输入" required />*</td>
						<td><div id="idDiv" style="display: inline"></div></td>
					</tr
					<tr>
						<td class="t1">最近停靠站：</td>
						<td><input name="location" type="text" class="c1"
							id="location" required> *</td>
						<td><div id="location" style="display: inline"></div></td>
					</tr>
					<tr>
						<td class="t1">当前状态：</td>
						<td><select name="status" id="status" value="${car.status}"
							class="c1">
								<option value="请选择">请选择</option>
								<option value="stop">停靠</option>
								<option value="way">在途</option>
						</select></td>
					</tr>
					<!-- 这里需要进行额外的设置，使得下拉列表中可以显示所有的类型 -->
					<tr>
						<td class="t1">车辆类型：</td>
						<td><select name="carType" class="c1" id="carType">
								<option value="请选择">请选择</option>
								<c:forEach items="${types}" var="t">
									<option value="${t.carTypeName}">${t.carTypeName}</option>
								</c:forEach>
						</select></td>
					</tr>
					<tr>
						<td class="t1">当前装载量：</td>
						<td><input name="carCurrent" type="text" id="carCurrent"
							class="c1">*</td>
					</tr>
					<tr>
						<td class="t1">操作：</td>
						<td><input name="Submit" type="submit" value="保存" class="c1"> &nbsp; <input name="Submit2"
							type="button" value="返回" onClick="history.back()" class="c1"></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		function checkform() { //状态与类型检查
			var pass = true;
			//车牌号检查
			var carId = $("#carId").val();
			var reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
			var pattern = new RegExp(reg);
			if (!(pattern.test(carId))) {//关于车牌号的检查
				alert("车牌号格式不正确");
				$("#carId").attr("value", "");//清空
				return false;
			} else{
				//进行ajax检验，查看是否与数据库中相同
				$.ajaxSettings.async = false;
				$.get(
					"/checkCarId",
					{carId:carId},
					function(data){
						console.log(data);
						if(data==1){
							alert("车牌号已存在");
							$("#carId").val("");//清空
							pass = false;
						}
					}
				);
			}
			return pass;
			//装载量检查
			var carCurrent = $("#carCurrent").val();
			reg = /^[0-9\.]{0,10}$/;
			var pattern2 = new RegExp(reg);
			if (!(pattern2.test(carCurrent))) {//关于装载量的检查
				alert("装载量只能填写数字");
				$("#carCurrent").attr("value", 0);//装载量为空的时候，自动将其设置成0
				return false;
			} 
			var status = $("#status").val();//状态获取
			var carType = $("#carType").val();//类型获取
			if (status == "请选择" || carType == "请选择") {
				alert("请选择当前状态和车辆类型");
				return false;
			}
		}
	</script>
</body>
</html>